<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
	public function index()
	{
		$this->display();
    }

    public  function login_user()
    {
    	// var_dump($_POST);die;
    	if (!IS_POST) {
    		echo "1";die;
    	}
    	$data['username'] = $_POST['username'];
    	$data['password'] = md5($_POST['password']);
    	$user = M('admin');
    	$user_name = $user->where(array('username'=>$data['username']))->find();
    	// var_dump($user_name);die;	 
    	if(!isset($user_name)){
    		echo "2";die;
    	}
    	if($user_name['status'] == 0){
			echo "4";die;
    	}
    	$pass = $user->where(array('password'=>$data['password']))->find();
    	if(!isset($pass)){
    		echo "3";die;
    	}
    	$list = array(
    		"id" 		=> $user_name['id'],
    		"update_at" => time(),
            "rip"       => $_SERVER['SERVER_ADDR'],
    		);	
    
    	if ($user->save($list)) {
    		session('lampzuo_id',$user_name['id']);
			$url = U('Index/index');
            echo "5#".$url;die;
    	}
    }

    //退出
    public function logout()
    {
        session('lampzuo_id',null);
        redirect(U('Login/index'));
    }
}
